#include "MouseManager.h"
#include "Common.h"
#include "Viewport.h"
#include "GraphicsDeviceManager.h"

MouseManager::MouseManager()
{
}

MouseManager::~MouseManager()
{
}

MouseManager* MouseManager::GetInstance()
{
	if(m_pInstance == NULL)
	{
		m_pInstance = new MouseManager();
	}

	return m_pInstance;
}

void MouseManager::Update()
{
	memcpy(&m_oPreviousState, &m_oCurrentState, sizeof(MouseState));

	m_oCurrentState = MouseState::GetState();
}

Vector2i MouseManager::GetPosition() const
{
	return m_oCurrentState.GetPosition();
}

Vector2i MouseManager::GetPositionChange() const
{
	return m_oCurrentState.GetPosition() - m_oPreviousState.GetPosition();
}

void MouseManager::SetPosition(const Vector2i& position) const
{
	glfwSetMousePos(position.X, position.Y);
}

void MouseManager::SetVisible(bool visible) const
{
	if(visible)
	{
		glfwEnable(GLFW_MOUSE_CURSOR);
	}
	else
	{	
		glfwDisable(GLFW_MOUSE_CURSOR);
	}
}

int MouseManager::GetWheel() const
{
	return m_oCurrentState.GetWheel();
}

int MouseManager::GetWheelChange() const
{
	return m_oCurrentState.GetWheel() - m_oPreviousState.GetWheel();
}

bool MouseManager::IsButtonDown(MouseButtons button) const
{
	return m_oCurrentState.IsButtonDown(button);
}

bool MouseManager::IsButtonUp(MouseButtons button) const
{
	return m_oCurrentState.IsButtonUp(button);
}

bool MouseManager::IsButtonPressed(MouseButtons button) const
{
	return m_oCurrentState.IsButtonDown(button) && m_oPreviousState.IsButtonUp(button);
}

 bool MouseManager::IsButtonReleased(MouseButtons button) const
{
	return m_oCurrentState.IsButtonUp(button) && m_oPreviousState.IsButtonDown(button);
}

MouseManager* MouseManager::m_pInstance = NULL;